#!/bin/bash
#function: set mysqld 5.7 password and start mysqld 5.7
#parmeter:
#author: yeslf
#version: 1.0
#Test: CentOS6

echo >/var/log/mysqld.log

service mysqld start

pass=$(grep oot@localhost /var/log/mysqld.log |awk  -F"root@localhost:"  '{print $2}')

mysqladmin -u root -p`echo $pass`  password 'TokT123j.:'

mysql -u root -p'TokT123j.:' -e "CREATE USER 'mysqlroot'@'%' IDENTIFIED BY 'T.test123'"
mysql -u root -p'TokT123j.:' -e "CREATE USER 'mysqlroot'@'localhost' IDENTIFIED BY 'T.test123'"
mysql -u root -p'TokT123j.:' -e "CREATE USER 'mysqlroot'@'127.0.0.1' IDENTIFIED BY 'T.test123'"
mysql -u root -p'TokT123j.:' -e "GRANT ALL PRIVILEGES ON *.* TO 'mysqlroot'@'%' WITH GRANT OPTION"


service mysqld stop 

chown -R mysql:mysql /var/lib/mysql

mysqld_safe 


